<?php
/**
 * User: AK.
 * Date: 2019/7/17
 * 完成用户登录、注册、验证token等功能
 */
class Article extends CI_Model{

	

   //获取app_menu父目录数据
   public function get_app_menu()
   {
        $this->db->select("*");
        $this->db->where("pmenuid",0);
        $this->db->order_by("orderid","ASC");
        $this->db->from("store_app_menu");
        $query = $this->db->get();
        if($query->num_rows() < 1)
            return false;
        return $query->result_array();    
   }
      
   
    //获取app_menu子目录数据
   public function get_app_submenu($pmenuid)
   {
        $this->db->select("*");
        $this->db->where("pmenuid",$pmenuid);
        $this->db->order_by("orderid","ASC");
        $this->db->from("store_app_menu");
        $query = $this->db->get();
        if($query->num_rows() < 1)
            return false;
        return $query->result_array();    
   }
   
   //设置自定义菜单
   public function set_user_menu($mymenu,$userid)
   {
		$this->db->where("userid",$userid);
		//base64加密
		$data['mymenu'] = $mymenu;
		if($this->db->update('app_user',$data)){
			return true;
		}else{
			return false;
		}
   }  
    
	/*
		说明：插入用户读取的信息数据
		date：2019-09-10日
	*/

   public function insert_appuser_read($userid,$newsid,$channel,$type)
   {

		if(isset($userid) && isset($newsid) && isset($channel) ){
			$data['userid'] = $userid;
			$data['newsid'] = $newsid;
			$data['channel'] = $channel;
			$data['readdate'] = time();
			$data['type'] = $type;
			$this->db->insert('app_user_read_counts',$data);
			return true;
		}
		return false;
	}

	/*
		说明：返回用户当天读取的信息条数
		date：2019-09-10日
	*/

   public function get_appuser_max_news($userid,$channel,$type)
   {

		$this->db->select("distinct(newsid) as id ");
		$this->db->where("userid",$userid);
		$this->db->where("channel",$channel);
		$this->db->where("type",$type);
		$this->db->from('app_user_read_counts');
        $query = $this->db->get();
		$counts = 0;
        if($query->num_rows() > 1)
            $counts = 	$query->num_rows();	
		
		return $counts;		

	}

}